import 'package:flutter/material.dart';

class Exam extends Notification {
  String id;
  String courseId;
  String name;
  ExamStatus status;
  int type;
  DateTime startTime;
  DateTime endTime;
  int duration;
  double score;
  int quesCount;
  bool isPass;
  bool isJoin;

  Exam({
    this.id,
    this.courseId,
    this.name,
    this.type,
    /* 课程使用此字段 */
    this.status,
    this.startTime,
    this.endTime,
    this.duration,
    this.score,
    this.quesCount,
    this.isPass,
    this.isJoin,
  });

  static Exam fromJson(Map<String, dynamic> json) {
    return new Exam(
      id: json['id'],
      courseId: json['courseId'] ?? '',
      name: json['name'],
      type: json['type'],
      status: ExamStatus.values[json['examStartType']],
      startTime: json['startTime'] == null ? null : DateTime.parse(json['startTime']),
      endTime: json['endTime'] == null ? null : DateTime.parse(json['endTime']),
      duration: json['duration'] ?? 0,
      score: json['score'] ?? -1.0,
      quesCount: json['quesCount'] ?? 0,
      isPass: json['pass'] ?? false,
      isJoin: json['pass'] != null,
    );
  }
}

enum ExamStatus {
  NotStarted,
  Started,
  Ended,
}

class ExamProfile {
  String id;
  String name;
  DateTime date;

  ExamProfile({this.id, this.name, this.date});

  factory ExamProfile.fromJson(Map<String, dynamic> json) {
    return ExamProfile(
      id: json['id'],
      name: json['examName'],
      date: json['startTime'] == null ? null : DateTime.parse(json['startTime']),
    );
  }
}
